{template 'common/header'}
<style type="text/css">
	.history_no_nav {height:38px; width:43%; background:#eee; margin:0px 3%; float:left; border:1px solid #d4d4d4; border-radius:5px; text-align:center; line-height:38px; color:#666;}
	.history_no {height:100px; width:100%; margin:50px 0px 60px; color:#ccc; font-size:12px; text-align:center;}
	.history_no_menu {height:40px; width:100%;}
	.history_no_nav {height:38px; width:43%; background:#eee; margin:0px 3%; float:left; border:1px solid #d4d4d4; border-radius:5px; text-align:center; line-height:38px; color:#666;}
	#history_loading { padding:10px;color:#666;text-align: center;}
</style>
<div id='container'></div>
<script id='history_empty' type='text/html'>
	<div class="history_no"><i class="fa fa-history" style="font-size:100px;"></i><br><span style="line-height:18px; font-size:16px;">您没有浏览过任何商品</span><br>主人快去给我找点东西吧</div>
	<div class="history_no_menu">
		<div class="history_no_nav" onclick="location.href='{php echo $this->createMobileUrl('member')}'">个人中心</div>
		<div class="history_no_nav"  onclick="location.href='{php echo $this->footer['first']['url']}'">去逛逛</div>
	</div>
</script>
<script id="history_main" type="text/html">
	<div class="mui-content content-bg-w7">
		<header id="header" class="mui-bar mui-bar-nav">
			<button class="mui-action-back mui-btn mui-btn-blue mui-btn-link mui-btn-nav mui-pull-left header-back-icon">
				<span class="mui-icon mui-icon-left-nav"></span>
				我的足迹
			</button>
		</header>
		<div class="list-foot-print history_main"></div>
	</div>
</script>
<script id='history_list' type='text/html'>
	<div class="list-order">
		<ul class="list-group-order">
			<%each list as value%>
			<li class="list-item-order list-item-foot-print history_good" data-historyid="<%value.id%>">
				<div class="mid-content-order white-bg">
					<div class="pic-goods-order">
						<img src="<%value.thumb%>" alt="" />
					</div>
					<div class="info-goods-order">
						<div class="goods-name-order"><%value.title%></div>
						<div class="goods-intro-order">￥<%value.marketprice%> <span style="color:#666;font-size:12px;text-decoration:line-through;">￥<%value.productprice%><span></div>
					</div>
					<div class="info-goods-num-order remove">
						<span class="mui-icon mui-icon-close"></span>
					</div>
				</div>
			</li>
			<%/each%>
		</ul>
	</div>
</script>
<script language='javascript'>
	var page= 1;
	require(['tpl', 'core'], function(tpl, core) {
		function bindEvents(){
			$('.remove').click(function(){
				var th = $(this);
				var ids = [ $(this).closest('.history_good').data('historyid') ];
				removeHistory(ids,th);
			});
		}

		function removeHistory(ids,th){
			if(ids.length<=0){
				mui.toast('未选择商品');
				return;
			}
			var btnArray = ['是', '否'];
			mui.confirm('确认删除该足迹？', '温馨提示', btnArray, function(e){
				if(e.index == 0) {
					$('.history_good').attr('del', 0);
					core.json('shop/history', {'op': 'remove', ids: ids}, function (json) {
						if (json.status == 1) {
							//删除操作
							mui.toast('足迹已删除！');
							th.parents('.list-item-foot-print').remove()
						} else {
							mui.toast('删除失败');
						}
					}, true, true);
				}
			});
		}
		core.json('shop/history',{},function(json){
			if(json.result.total<=0){
				$('#container').html(  tpl('history_empty') );
				return;
			}
			$('#container').html(  tpl('history_main',json.result) );
			$('.history_main').html(  tpl('history_list',json.result) );
			bindEvents();
			var loaded = false;
			var stop=true;
			$(window).scroll(function(){
				if(loaded){
					return;
				}
				totalheight = parseFloat($(window).height()) + parseFloat($(window).scrollTop());
				if($(document).height() <= totalheight){
					if(stop==true){
						stop=false;
						$('.history_main').append('<div id="history_loading"><i class="fa fa-spinner fa-spin"></i> 正在加载...</div>');
						page++;
						core.json('shop/history', {page:page}, function(morejson) {
							stop = true;
							$('#history_loading').remove();
							$(".history_main").append(tpl('history_list', morejson.result));
							bindEvents();
							if (morejson.result.list.length <morejson.result.pagesize) {

								$('.history_main').append('<div id="history_loading">已经加载完全部足迹</div>');
								loaded = true;
								$(window).scroll = null;
								return;
							}
						},true);
					}
				}
			});
		},true);
	});
</script>
{php $show_footer = true}
{template 'common/footer'}